package com.kai.common.data;

import com.kai.common.exception.ErrorCodeConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;

/**
 * 统一分页返回结果
 *
 * @param <T>
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class PagingResult<T> extends Result<List<T>> implements Serializable {

    private static final long serialVersionUID = 2008968116071100625L;

    private long pageIndex;

    private long pageSize;

    private long total;

    public PagingResult(List<T> body, long pageIndex, long pageSize, long total) {
        super(body, ErrorCodeConstants.SUCCESS.getCode(), ErrorCodeConstants.SUCCESS.getMsg(), true);
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.total = total;
    }

    public static <T> PagingResult<T> success(List<T> body, long pageIndex, long pageSize, long total) {
        return new PagingResult<>(body, pageIndex, pageSize, total);
    }
}